package com.android.job.util;

import java.io.File;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Handler;
import android.os.Message;

import com.android.job.fusion.FusionField;

public class CommonUtil
{

	 /**
     * 发送Handler消息
     * 
     * @param handler
     * @param what
     * @param o
     */
    public static void sendMessage(Handler handler, int what, Object o)
    {
        Message msg = new Message();
        msg.what = what;
        msg.obj = o;
        handler.sendMessage(msg);

    }
    
    /**
     * 取得版本号、包名、版本名
     * 
     * @return
     */
    public static String getVersionName()
    {
        String versionName = "";
        try
        {
            PackageManager manager = FusionField.currentActivity
                    .getPackageManager();
            PackageInfo info = manager.getPackageInfo(
                    FusionField.currentActivity.getPackageName(), 0);
            versionName = info.versionName; // 版本名
        }
        catch (NameNotFoundException e)
        {
            e.printStackTrace();
        }
        return versionName;
    }
    
	/**
	 * 判断存储卡是否存在
	 * 
	 * @return
	 */
	public static boolean existSDcard()
	{
		if (android.os.Environment.MEDIA_MOUNTED.equals(android.os.Environment
				.getExternalStorageState()))
		{
			return true;
		}
		else
		{
			return false;
		}
			
	}
	
	/**
	* 在程序第一次安装的时候就在sd卡的主目录下新建一个系统所需的目录 
	* @return   创建目录是否成功
	*/
	public static boolean makeDir()
	{
		boolean isComplete = false;

		// 创建下载目录

		File fileupdate = new File(FusionField.UPDATE_VERSION_SAVEPATH);
		if (!FileHelper.isFileExist(fileupdate))
		{
			isComplete = fileupdate.mkdirs();
		}
		return isComplete;
	}
	
    
}
